import os

import pymysql
import pytest,requests
from dotenv import load_dotenv
load_dotenv()
@pytest.fixture(scope='function')
def login_token():
    url = 'http://10.59.9.18/small/user/v1/login'
    header = {'Content-Type': 'application/json'}
    data = {
            "phone": os.getenv('LOGIN_PHONE'),
            "pwd": os.getenv('LOGIN_PWD'),
            
           }
    res = requests.post(url=url, headers=header, json=data)
    print(res.json())
    login_json = res.json()
    yield login_json['result']['sessionId'],login_json['result']['userId']

    db_database("田够够","17666666888","北京八维")

    # 数据库清理
def db_database(real_name,phone,address):
    conn=pymysql.connect(
        host = '10.59.9.19',
        user = 'yidongceshi',
        password = 'Yd123456!',
        db ='mall'
    )
    # cur=conn.cursor()
    # query='DELETE FROM receive_address WHERE real_name=%s and phone=%s and address =%s'
    # cur.execute(query,(real_name,phone,address))